import request from '@/utils/request';
import {AxiosPromise} from 'axios';
import {CreateRepoCompRequestVO, RepoCompPageResult, RepoCompQueryParam,} from './types';

export function listRepoCompEntityPages(queryParams: RepoCompQueryParam): AxiosPromise<RepoCompPageResult> {
    return request({
        url: '/manager/repository/component/page',
        method: 'post',
        data: queryParams,
    });
}

export function createRepoCompEntity(data: CreateRepoCompRequestVO) {
    return request({
        url: '/manager/repository/component/entity',
        method: 'post',
        data: data,
    });
}

export function updateRepoCompEntity(data: CreateRepoCompRequestVO) {
    return request({
        url: '/manager/repository/component/entity',
        method: 'put',
        data: data,
    });
}

export function deleteRepoCompEntity(data: CreateRepoCompRequestVO) {
    return request({
        url: '/manager/repository/component/entity',
        method: 'delete',
        params: {
            modelName: data.modelName,
            modelType: data.modelType,
            modelVersion: data.modelVersion,
        },
    });
}

export function deleteRepoCompVerEntity(data: CreateRepoCompRequestVO) {
    return request({
        url: '/manager/repository/component/version',
        method: 'delete',
        params: {
            modelName: data.modelName,
            modelType: data.modelType,
            modelVersion: data.modelVersion,
            version: data.version,
            stage: data.stage,
        },
    });
}

export function updateRepoCompVerEntity(data: CreateRepoCompRequestVO) {
    return request({
        url: '/manager/repository/component/version',
        method: 'put',
        data: {
            modelName: data.modelName,
            modelType: data.modelType,
            modelVersion: data.modelVersion,
            version: data.version,
            stage: data.stage,
            newStage: data.newStage,
        },
    });
}

export function downloadRepoCompVerEntity(data: CreateRepoCompRequestVO) {
    return request({
        url: '/manager/repository/component/download',
        method: 'post',
        data: data,
        responseType: 'blob',
    });
}

export function updateRepoCompCommitKey(data: CreateRepoCompRequestVO) {
    return request({
        url: '/manager/repository/component/commitKey',
        method: 'put',
        data: {
            id: data.id,
            commitKey: data.commitKey,
        },
    });
}